package com.hellobike.haxing.modules.statics.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hellobike.haxing.common.annotation.AutoLog;
import com.hellobike.haxing.common.vo.Result;
import com.hellobike.haxing.modules.order.entity.ShopStaticsVo;
import com.hellobike.haxing.modules.order.mapper.OrderMapper;
import com.hellobike.haxing.modules.statics.dto.ProductStats;
import lombok.extern.slf4j.Slf4j;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: t_wms_asn_detail
 * @Author: haxing-boot
 * @Date: 2020-01-09
 * @Version: V1.0
 */
@RestController
@RequestMapping("/statics/promoter")
@Slf4j
public class PromoterStaticsController {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 分页列表查询
     *
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "推广员统计-导出")
    @GetMapping(value = "/export")
    public ModelAndView queryPageList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10000000") Integer pageSize,
            ShopStaticsVo request,
            HttpServletRequest req) {
        IPage<ShopStaticsVo> page = new Page<>(pageNo, pageSize);
        IPage<ShopStaticsVo> pageList = orderMapper.selectShopStatics(page, request);
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        mv.addObject(NormalExcelConstants.FILE_NAME, "团长统计");
        mv.addObject(NormalExcelConstants.CLASS, ProductStats.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("团长统计", null, "团长统计"));
        mv.addObject(NormalExcelConstants.DATA_LIST, pageList.getRecords());
        return mv;
    }

    /**
     * 分页列表查询
     *
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "推广员统计-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> list(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10000000") Integer pageSize,
            ShopStaticsVo request,
            HttpServletRequest req) {
        IPage<ShopStaticsVo> page = new Page<>(pageNo, pageSize);
        IPage<ShopStaticsVo> pageList = orderMapper.selectShopStatics(page, request);
        return Result.ok(pageList);
    }
}
